﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SES.CMS.BL;
using SES.CMS.DO;

namespace SES.CMS.Module
{
    public partial class ucHomeArticle : System.Web.UI.UserControl
    {
        cmsArticleBL artBL = new cmsArticleBL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
            //    rptHomepageArticleDatasource();
                ArticleDatabind();
            }
        }

        protected void rptHomepageArticleDatasource()
        {
            rptHomepageArticle.DataSource = artBL.SelectToHomePage(3);
            rptHomepageArticle.DataBind();
        }

        protected void ArticleDatabind()
        {
            DataTable dtArticle = artBL.SelectToHomePage(6);
            if (dtArticle.Rows.Count > 0)
            {
                imgArticle.ImageUrl = "/Media/" + dtArticle.Rows[0]["ImageUrl"];
                imgArticle.AlternateText = dtArticle.Rows[0]["Title"].ToString();

                hplTitle.NavigateUrl = "/Article/" + dtArticle.Rows[0]["ArticleID"] + "/" + FriendlyUrl(dtArticle.Rows[0]["Title"].ToString());
                hplTitle.Text = dtArticle.Rows[0]["Title"].ToString();

                ltrArticleDes.Text = WordCut(dtArticle.Rows[0]["Description"].ToString());
                rptHomepageArticle.DataSource = new DataView(dtArticle, "ArticleID <> " + dtArticle.Rows[0]["ArticleID"], "", DataViewRowState.CurrentRows);
                rptHomepageArticle.DataBind();
            }

        }

        public string FriendlyUrl(string s)
        {
            return Ultility.Change_AV(s);
        }
        public string WordCut(string text)
        {
            return Ultility.WordCut(text, 260, new char[] { ' ', '.', ',', ';' }) + "...";
        }
    }
}